import { feedSign, getZhuangyuanInfo, feedChick, changePointsToFeed,transferGoodParam } from 'config/api';
import { Toast } from 'antd-mobile';
export default {
  namespace: 'yangji',
  state: {
    feed: 0,
    feed_has_eat: 0,
    egg: 0,
    points: 0,
    headimgurl: ''
  },
  effects: {
    *getZhuangyuanInfoEff(action, { call, put }) {
      let response = yield call(getZhuangyuanInfo);
      console.log("​*getZhuangyuanInfoEff -> response", response)
      yield put({
        type: 'save',
        payload: response
      })
    },
    *feedSignEff({ callback }, { call, put }) {
      let { code, msg } = yield call(feedSign);
      if (code === 0) {
        callback();
        yield put({
          type: 'getZhuangyuanInfoEff'
        })
      } else {
        Toast.fail(msg);
      }
    },
    *feedChickEff(action, {call, put}){
      let {code,msg} = yield call(feedChick)
      if(code === 0){
        Toast.success(msg)
        yield put({
          type: 'getZhuangyuanInfoEff'
        })
      }else{
        Toast.info(msg)
      }
    },
    *changePointsToFeedEff({pointsToChange}, {call, put}){
      let {code,msg} = yield call(changePointsToFeed, {pointsToChange})
      if(code === 0){
        Toast.success(msg)
        yield put({
          type: 'getZhuangyuanInfoEff'
        })
      }else{
        Toast.info(msg)
      }
    },
    // *sendgoodEff({count,goodType},{call, put, select}){
    // //  let  res = yield call(transferGoodParam, {count,goodType})
    //  console.log("​*sendgoodEff -> res", res)
    // }
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    }
  }
};
